From c4af1f2aa5993c694fcd096a7e99bde095fd9efc Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Mon, 20 May 2024 15:07:17 -0700
Subject: fix(badges): null check preferences

---
 src/routes/user/[user]/badges/+page.svelte | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

(limited to 'src/routes/user/[user]/badges/+page.svelte')

diff --git a/src/routes/user/[user]/badges/+page.svelte b/src/routes/user/[user]/badges/+page.svelte
index 9e4ef7cf..d81cea28 100644
--- a/src/routes/user/[user]/badges/+page.svelte
+++ b/src/routes/user/[user]/badges/+page.svelte
@@ -96,7 +96,7 @@
 		awcPromise = fetch(proxy(`https://awc.moe/challenger/${badger.name}`));
 		preferences = await (await fetch(root(`/api/preferences?id=${badger.id}`))).json();
 
-		if (preferences.badge_wall_css) {
+		if (preferences && preferences.badge_wall_css) {
 			const sanitise = (css: string) =>
 				css
 					.replace(/\/\*[\s\S]*?\*\//g, '')
@@ -272,7 +272,10 @@
 		return Object.entries(groupedBadges)
 			.sort((a, b) => a[1].length - b[1].length)
 			.sort((a, b) => {
-				const pinnedCategories = preferences.pinned_badge_wall_categories || ([] as string[]);
+				const pinnedCategories =
+					preferences && preferences.pinned_badge_wall_categories
+						? preferences.pinned_badge_wall_categories
+						: ([] as string[]);
 				const aIndex = pinnedCategories.indexOf(a[0]);
 				const bIndex = pinnedCategories.indexOf(b[0]);
 
@@ -484,7 +487,7 @@
 						!editMode}
 
 					<div id="badges">
-						{#if !preferences.hide_awc_badges}
+						{#if preferences && !preferences.hide_awc_badges}
 							<AWC {awcPromise} {categoryFilter} {isOwner} {preferences} />
 						{/if}
 
-- 
cgit v1.2.3

